/*
data in the "in.txt"

4
341
34200
5910000
1000000000
*/

/*
Makefile:


CC = gcc
CFLAGS = -gdwarf-2 -g3
LIBS = 

All: PrettyPrint

PrettyPrint:
	$(CC) $(CFLAGS) PrettyPrint.c -o PrettyPrint

clean:
	rm -f *.o

*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

// insert template using emacs
#define FILEIO

int main(int argc,char **argv) 
{ 

#ifdef FILEIO
	freopen("in.txt","r",stdin); 
	freopen("out.txt","w",stdout); 
#endif

	int N;
	scanf("%d\n",&N);

	int array[10];
	int index=0;
	int number=0;
	int temp=0;
	int m;
	int start;
	int offset=3;

	for(int i=0;i<N;i++)
	{
		scanf("%d",&number);
		memset(array,0,sizeof(int)*10);    
		index = 0;
		temp = number; 
		while(temp > 0)
		{
			array[index++] = temp%10;
			temp = temp/10;
		}

		//printf("%d\n",index);

		if(index >= 10)
		{
			printf("%dG\n",number/1000000000);
		}
		else if(index > 6)
		{
			start = index - 1;
			for(m = start;m>start - offset;m--)
			{
				if(m==5)
					printf(".");
				printf("%d",array[m]);
			}
			printf("M\n");
		}
		else if(index > 3)
		{
			start = index-1;
			for(m = start;m>start - offset;m--)
			{
				if(m==2)
					printf(".");
				printf("%d",array[m]);
			}
			printf("K\n");
		}
		else
			printf("%dB\n",number);

	}

#ifdef FILEIO
	fclose(stdin);
	fclose(stdout);
#endif  

	return 0; 
}
